﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;


namespace GoogleMapsAPI
{
    public partial class frmMarker : Form
    {
        public string lat;
        public string lng;
        frmMain frmmain;

        public frmMarker(frmMain main)
        {
            InitializeComponent();
            frmmain = main;
        }

        private void btnthemdd_Click(object sender, EventArgs e)
        {
            try
            {
                Data newdata = new Data();
                if (cbloaidd.SelectedIndex != -1)
                    newdata.Group = cbloaidd.Text;
                newdata.Name = txttendiadiem.Text;
                newdata.Lat = textBox1.Text;
                newdata.Lng = textBox2.Text;
                Data.InsertPlace(newdata);
                MessageBox.Show("Succeed.");
                frmmain.clearTree();
                frmmain.LoadTreeView();
            }
            catch (Exception EX)
            {
                MessageBox.Show("Fail.");
                
            }
           
        }

        private void frmMarker_Load(object sender, EventArgs e)
        {
            loadcombo();
            textBox1.Text = lat;
            textBox2.Text = lng;
        }

        public void loadcombo()
        {
            List<XElement> list = Data.ReadData();
            foreach (XElement element in list)
            {
                string temp = element.Attribute("name").Value;
                cbloaidd.Items.Add(temp);
            }
        }

        public void clearcombo()
        {
            cbloaidd.Items.Clear();
        }

        private void btnthemloai_Click(object sender, EventArgs e)
        {
            frmloaidiadiem frm = new frmloaidiadiem(frmmain,this);
            frm.ShowDialog();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
